﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Assignment2
{
    public class PricingModel
    {
        //************************************************************************
        //*
        //*  Member variables
        //*
        //************************************************************************

        private static Int32 _chickenPrice;
        private static Dictionary<int, int> _simplePriceTable;
        private static Dictionary<int, int> _advancedPriceTable;

        //************************************************************************
        //*
        //*  Constructor
        //*
        //************************************************************************

        public PricingModel()
        {
            _chickenPrice = 1000;

            // simulates a simple bell curve based on the first digit of
            // the seconds the price was requested
            _simplePriceTable = new Dictionary<int, int>()
            {
                { 0, 1000},
                { 1, 2000},
                { 2, 3000},
                { 3, 2500},
                { 4, 1500},
                { 5, 900}
            };

            // Time span per shipment is 1 minute
            // Time/Price is determined by the second count

            // Simulates the following scenario:
            // 1.  Price starts low at the beginning of the time cycle representing
            //     the arrival of a new shipment.
            // 2.  Price spikes briefly as "pre-orders" are places
            // 3.  Price drops slightly after pre-orders have completed
            // 4.  Price jumps again as the normal order traffic occurs toward the middle
            //     of the cycle.
            // 5.  Price drops off after the normal orders are placed.
            // 6.  Price spikes slightly at the end as "last minute orders" are placed.
            // 7.  Price drops off to try to unload stock before the next shipment arrives.

            _advancedPriceTable = new Dictionary<int, int>()
            {
                {  0,  900},{  1,  910},{  2,  920},{  3,  930},{  4,  940},
                {  5,  950},{  6,  960},{  7,  970},{  8,  980},{  9,  990},
                { 10, 1000},{ 11,  990},{ 12,  980},{ 13,  970},{ 14,  960},
                { 15,  970},{ 16,  980},{ 17,  990},{ 18, 1000},{ 19, 1100},
                { 20, 1200},{ 21, 1300},{ 22, 1400},{ 23, 1500},{ 24, 1600},
                { 25, 1700},{ 26, 1800},{ 27, 1900},{ 28, 2000},{ 29, 2100},
                { 30, 2200},{ 31, 2100},{ 32, 2000},{ 33, 1900},{ 34, 1800},
                { 35, 1700},{ 36, 1600},{ 37, 1500},{ 38, 1400},{ 39, 1300},
                { 40, 1200},{ 41, 1100},{ 42, 1000},{ 43,  990},{ 44,  980},
                { 45,  970},{ 46,  950},{ 47,  960},{ 48,  970},{ 49,  980},
                { 50,  990},{ 51, 1000},{ 52,  980},{ 53,  970},{ 54,  960},
                { 55,  950},{ 56,  940},{ 57,  930},{ 58,  920},{ 59,  910}
            };
        }

        //************************************************************************
        //*
        //*  Calculate and return the current price
        //*
        //************************************************************************

        public Int32 getPrice() 
        {
            _chickenPrice = _getPriceFromComplexTable();
            return _chickenPrice; 
        }

        //************************************************************************
        //*
        //*  Get the current pice from the price table using a simple table
        //*
        //************************************************************************

        private Int32 _getPriceFromSimpleTable()
        {
            int seconds = DateTime.Now.Second / 10;
            Int32 price = _simplePriceTable[seconds];

            return price;
        }

        //************************************************************************
        //*
        //*  Get the current pice from the price table using an advanced table
        //*
        //************************************************************************

        private Int32 _getPriceFromComplexTable()
        {
            int seconds = DateTime.Now.Second;
            Int32 price = _advancedPriceTable[seconds];

            return price;
        }
    }
}
